<?php
/**
 * Talents come from diligence, and knowledge is gained by accumulation.
 *
 * @author: 晋<657306123@qq.com>
 * @date: 2019/8/5 16:31
 */

namespace xin\articlecollect\driver;

use QL\Dom\Elements;
use QL\QueryList;
use xin\articlecollect\AbsArticleCollect;

class Sohu extends AbsArticleCollect{

	/**
	 * 内容解析
	 *
	 * @param string $data HTML内容
	 * @return array
	 */
	public function parse($data){
		$query = QueryList::html($data);
		$title = $query->find('.text-title h1')->text();

		$createTime = $query->find('#news-time')->text();
		$createTime = strtotime($createTime);

		$viewCount = 0;

		$content = $query->find('.article');
		$content->find('[data-role="original-title"]')->remove();
		$content = $content->html();

		return [
			'title'       => $title,
			'content'     => $content,
			'view_count'  => $viewCount,
			'create_time' => $createTime,
		];
	}
}
